package vn.lumi.smarthome.ui;

import vn.lumi.smarthome.LumiHome;
import vn.lumi.smarthome.R;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.widget.Button;
import android.widget.TextView;

public class DialogLumi {
	public static void showAlertDialogBoth(Context mContext,
			final DialogInterfaceLumi dialogInterface, String title,
			String message) {
		AlertDialog.Builder dialog = new AlertDialog.Builder(
				new ContextThemeWrapper(mContext, R.style.AlertDialogCustom));

		ChangeFont changeFont = new ChangeFont(mContext);
		TextView tvTitle = new TextView(mContext);
		tvTitle = changeFont.changeFontTextView(tvTitle, title,
				LumiHome.fontBold, LumiHome.sizeTittle, Gravity.CENTER,
				mContext.getResources().getColor(R.color.green));
		dialog.setCustomTitle(tvTitle);

		dialog.setMessage(message);
		dialog.setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
						dialogInterface.OnClickCancel();
					}
				});
		dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				dialog.cancel();
				dialogInterface.OnClickOk();
			}
		});
		AlertDialog alertErrorDialog = dialog.create();
		alertErrorDialog.show();
		alertErrorDialog.getWindow().getAttributes();
		TextView tvMessage = (TextView) alertErrorDialog
				.findViewById(android.R.id.message);
		tvMessage = changeFont.changeFontTextView(tvMessage, message,
				LumiHome.font, LumiHome.sizeContent, Gravity.NO_GRAVITY,
				mContext.getResources().getColor(R.color.greenLight));

		Button btn1 = alertErrorDialog
				.getButton(DialogInterface.BUTTON_NEGATIVE);
		btn1.setTypeface(Typeface.createFromAsset(mContext.getAssets(),
				LumiHome.fontBold));
		btn1.setTextColor(mContext.getResources().getColor(
				R.color.greenActionbar));
		btn1.setTextSize(LumiHome.sizeButton);

		Button btn2 = alertErrorDialog
				.getButton(DialogInterface.BUTTON_POSITIVE);
		btn2.setTypeface(Typeface.createFromAsset(mContext.getAssets(),
				LumiHome.fontBold));
		btn2.setTextColor(mContext.getResources().getColor(
				R.color.greenActionbar));
		btn2.setTextSize(LumiHome.sizeButton);
	}

	public static void showAlertDialog(Context context,String title, String message) {
		AlertDialog.Builder ErrorDialog = new AlertDialog.Builder(
				new ContextThemeWrapper(context,
						R.style.AlertDialogCustom));

		ChangeFont changeFont = new ChangeFont(context);
		TextView tvTitle = new TextView(context);
		tvTitle = changeFont.changeFontTextView(tvTitle, title,
				LumiHome.fontBold, LumiHome.sizeTittle, Gravity.CENTER,
				context.getResources().getColor(R.color.green));
		ErrorDialog.setCustomTitle(tvTitle);
		ErrorDialog.setMessage(message);
		ErrorDialog.setNegativeButton(R.string.glb_txt_return,
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		AlertDialog alertErrorDialog = ErrorDialog.create();
		alertErrorDialog.show();
		alertErrorDialog.getWindow().getAttributes();
		TextView tvMessage = (TextView) alertErrorDialog
				.findViewById(android.R.id.message);
		tvMessage = changeFont.changeFontTextView(tvMessage, message,
				LumiHome.font, LumiHome.sizeContent, Gravity.NO_GRAVITY,
				context.getResources().getColor(R.color.greenLight));

		Button btn1 = alertErrorDialog
				.getButton(DialogInterface.BUTTON_NEGATIVE);
		btn1.setTypeface(Typeface.createFromAsset(context.getAssets(),
				LumiHome.fontBold));
		btn1.setTextColor(context.getResources().getColor(R.color.greenActionbar));
		btn1.setTextSize(LumiHome.sizeButton);
	}

	public static ProgressDialog showProgressDialogLumi(Context context,
			String message) {
		ProgressDialog dialog = new ProgressDialog(new ContextThemeWrapper(
				context, R.style.AlertDialogCustom));
		dialog.setMessage(message);
		dialog.setCancelable(false);
		dialog.show();
		// Thay doi font chu cua Dialog
		ChangeFont changeFont = new ChangeFont(context);
		TextView textView = (TextView) dialog
				.findViewById(android.R.id.message);
		textView = changeFont.changeFontTextView(textView, message,
				LumiHome.font, LumiHome.sizeContent, Gravity.NO_GRAVITY,
				context.getResources().getColor(R.color.greenActionbar));
		return dialog;

	}

	public static void cancelProgressDialogLumi(ProgressDialog dialog) {
		if (dialog != null && dialog.isShowing())
			dialog.dismiss();
	}
}
